package com.wws.family.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.wws.family.R
import com.wws.family.databinding.WidgetInputBinding

/**
 *@Description: 自定义输入
 *@Date: 2025/1/8 8:48
 *@Author: WangWeiShuo
 */
class WidgetInput @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet?,
    def: Int = -1
) : LinearLayout(context, attributeSet, def) {

    private var binding: WidgetInputBinding? = null

    init {
        binding = WidgetInputBinding.inflate(LayoutInflater.from(context), this, true)
        initParams(attributeSet, def)
        initView()
    }

    private fun initParams(attributeSet: AttributeSet?, def: Int) {
        context.theme.obtainStyledAttributes(
            attributeSet,
            R.styleable.WidgetInput,
            def, 0
        ).apply {
            val leftTitle = getString(R.styleable.WidgetInput_left_title)
            val inputContent = getString(R.styleable.WidgetInput_input_content)

            binding?.tvTitleName?.text = leftTitle
            binding?.etInput?.hint = inputContent
        }
    }

    private fun initView(){

    }

    override fun setOnClickListener(l: OnClickListener?) {
        binding?.root?.setOnClickListener {
            l?.onClick(it)
        }
    }

    fun setInputEnable(enable: Boolean){
        binding?.etInput?.isEnabled = enable
    }

    fun setInputMsg(msg: String?){
        binding?.etInput?.setText(msg)
    }

    fun getInputMsg(): String{
        return binding?.etInput?.text.toString()
    }
}